package com.teach.shape1;

import java.util.Scanner;

/**
 * 长方形
 * 
 * @author J.L.Zhou jlzhou.top 版权所有
 */
public class Trilateral {

	private static final String NAME = "三角形";
	/**
	 * 边一
	 */
	private float border1;
	/**
	 * 边二
	 */
	private float border2;
	/**
	 * 边三
	 */
	private float border3;

	/**
	 * 周长
	 */
	private float perimeter;

	/**
	 * 面积
	 */
	private float area;

	public void input(Scanner sc) {
//		while(true){
//			System.out.println("输入" + NAME + "的三边: ");
//			border1 = sc.nextFloat();
//			border2 = sc.nextFloat();
//			border3 = sc.nextFloat();
//			boolean flag = border1 + border2 > border3 && border1 + border3 > border2 && border2 + border3 > border1;
//			if(flag){
//				break;
//			}else{
//				System.out.println("您输入的三边不能构成"+NAME);
//			}
//		}
		System.out.println("输入" + NAME + "的三边: ");
		border1 = sc.nextFloat();
		border2 = sc.nextFloat();
		border3 = sc.nextFloat();
		boolean flag = border1 + border2 > border3 && border1 + border3 > border2 && border2 + border3 > border1;
		if(flag){
			perimeter = border1 + border2 + border3;
			float s = perimeter / 2;
			area = (float) Math.sqrt(s * (s - border1) * (s - border2) * (s - border3));
		}else{
			System.out.println("您输入的三边不能构成"+NAME);
			input(sc);//递归调用
		}
	}

	/**
	 * 获取周长
	 * 
	 * @return 周长
	 */
	public float getPerimeter() {
		return perimeter;
	}

	/**
	 * 获取面积
	 * 
	 * @return
	 */
	public float getArea() {
		return area;
	}

	/**
	 * 打印基本信息
	 */
	public void show() {
		System.out.format("%s\t周长：%.2f\t面积：%.2f\t三边：%.2f,%.2f,%.2f\n", NAME, perimeter, area, border1, border2,
				border3);

	}

	public float getBorder1() {
		return border1;
	}

	public void setBorder1(float border1) {
		this.border1 = border1;
	}

	public float getBorder2() {
		return border2;
	}

	public void setBorder2(float border2) {
		this.border2 = border2;
	}

	public float getBorder3() {
		return border3;
	}

	public void setBorder3(float border3) {
		this.border3 = border3;
	}

	public static void main(String[] args) {
		Trilateral rectangle = new Trilateral();
		rectangle.input(new Scanner(System.in));
		rectangle.show();
	}

}
